package logic

import (
	"context"
	"lucky/luckyrpc/luckyrpc"

	"lucky/api/internal/svc"
	"lucky/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProductListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewProductListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProductListLogic {
	return &ProductListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ProductListLogic) ProductList(req *types.ProductListRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	list, err := l.svcCtx.LuckyRpc.ProductList(l.ctx, &luckyrpc.ProductListRequest{
		Name:     req.Name,
		Taste:    req.Taste,
		MaxPrice: float32(req.MaxPrice),
		MinPrice: float32(req.MinPrice),
		Page:     req.Page,
		Limit:    req.Limit,
		Sort:     req.Sort,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    0,
		}, nil
	}
	return &types.Response{
		Message: "商品查询成功",
		Data:    list,
		Code:    200,
	}, nil
}
